package com.qdlc.p2p.biz.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;

import com.qdlc.p2p.common.constant.NotifyUrl;
import com.qdlc.p2p.common.util.DataUtils;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import com.qdlc.p2p.dal.common.SystemConfigHelper.Nid;


public class NotifyRequestUrl {

	//回调请求路径前缀
	public static final String URL_PREFIX = SystemConfigHelper.getValue(Nid.WEB_URL);
	//微信请求地址前缀
	public static final String WX_URL_PREFIX = SystemConfigHelper.getValue(Nid.WECHAT_URL);
	
	//提现请求回调
	public static final String ACTION_WITH_DRAW_URL = "/tpp/tppSinaAction/tppCashNotice";
	public static final String WITH_DRAW_URL = URL_PREFIX + ACTION_WITH_DRAW_URL + ".html";

	//代收回调地址
	public static final String COLLECT_TRADE_NOTIFY_URL = URL_PREFIX + "/tpp/tppSinaAction/tppCollectTradeNotify.html";

	//企业开户回调地址
	public static final String AUDIT_MEMBERINFOS_NOTIFY_URL = URL_PREFIX + "/tpp/tppSinaAction/tppAuditMemberInfosNotice.html";

	// 购买电影票代收异步回调
	public static final String COLLECT_TRADE_MOV_TIC_NOTIFY_URL = URL_PREFIX +"/tpp/tppSinaAction/tppCollectTradeMovTicNotify.html";

	// 购买电影票代付异步回调
	public static final String PAY_TRADE_MOV_TIC_NOTIFY_URL = URL_PREFIX +"/tpp/tppSinaAction/tppPayTradeMovTicNotify.html";

	// 充值页面资源地址
	public static final String RECHARGE_PAGE_NOTIFY_ACTION = "/member/recharge/newRecharge";
	public static final String RECHARGE_PAGE_NOTIFY_URL = URL_PREFIX + RECHARGE_PAGE_NOTIFY_ACTION + ".html";
	
	// 充值后台页面地址(Sina、Baofoo)
	public static final String RECHARGE_RETURN_NOTIFY_ACTION = "/notify/recharge/rechargeNotify";
	// 充值后台回调地址(Sina、Baofoo)
	public static final String RECHARGE_RETURN_NOTIFY_URL = URL_PREFIX + RECHARGE_RETURN_NOTIFY_ACTION + ".html";
	
	// 快捷支付通知地址(Sina)
	public static final String QUICK_PAY_NOTIFY_ACTION= "/tpp/tppSinaAction/quicklyPayNotify";
	public static final String QUICK_PAY_NOTIFY_URL = URL_PREFIX + QUICK_PAY_NOTIFY_ACTION + ".html";

	//微信页面资源地址
	public static final String WEIXIN_RECHARGE_PAGE_NOTIFY_ACTION = "/mobile/usercenter/recharge/newRecharge";
	public static final String WEIXIN_RECHARGE_PAGE_NOTIFY_URL =  WX_URL_PREFIX + WEIXIN_RECHARGE_PAGE_NOTIFY_ACTION + ".html";
	
    
    private static Set<String> filtedUrl;
    
    /**
     * 被过滤的通知Url
     * @return
     */
    public static Set<String> filtedNotifyUrl(){
    	if(filtedUrl == null){
    		filtedUrl();
    	}
    	return filtedUrl;
    }
    
    private synchronized static void filtedUrl(){
    	filtedUrl = new HashSet<String>();
    	Class<?>[] classes = new Class[]{NotifyUrl.class, NotifyRequestUrl.class};
    	for(Class<?> clazz: classes){
    		Field[] fields = clazz.getFields();
    		for(Field f: fields){
    			if((f.getModifiers() & Modifier.FINAL) != 0){
    				try {
    					String value = DataUtils.toString(f.get(null));
    					if("".equals(value)){
    						continue;
    					}
    					filtedUrl.add(value);
    				} catch (Exception ignore) {
    				}
    			}
    		}
    	}
    }
}
